public class Main {

    //整数拆解问题
    //门牌问题
    //求1 - 2020 之间有多少个2
    public static void main(String[] args) {
        int ret = 0;
        for (int i = 1; i <= 2020; i++) {
            ret += findNum(i);
        }
        System.out.println(ret);
    }

    private static int findNum(int k){
        int count = 0;
        while(k >= 1){
            int val = k % 10;
            if(val == 2){
                count++;
            }
            k /= 10;
        }
        return count;
    }


    public static void main1(String[] args) {
        int val = 0;
        for (int i = 1; i <= 2020 ; i++) {
            int x = i;
            while(x > 0){
                if(x % 10 == 2) val++;
                x /= 10;
            }
        }
        System.out.println(val);
    }
}
